#ifndef  __DOUBLE_LIST_H__
#define __DOUBLE_LIST_H__
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#include<math.h>

//定义节点
typedef struct Node
{
	int LPN;
	struct Node *Pre;
	struct Node *Next;
    int isD;
    int cold;
}Node ,*pNode;

int Min_lc;
int buf_size;
pNode HotHead,ColdHead;
int HotLength,ColdLength;
//相关的统计变量
int buffer_hit;
int buffer_miss;
int buffer_cnt;
int buffer_read_hit;
int buffer_read_miss;
int buffer_write_hit;
int buffer_write_miss;
int physical_read;
int physical_write;
int cache_write_num;
int cache_read_num;

//关于对其操作的红定义
#define SEC_PRE_PAGE 4
#define PAGE_PRE_BLK 64
#define SEC_PRE_BLK  256

#define CACHE_READ_DELAY 0.005
#define CACHE_WRITE_DELAY 0.005

//创建双向链表
pNode CreateList();
//初始化两个冷热队列
void InitDoubleList();
void InitVariable();
void resetCacheStat();
void DestoryDouleList();
//判断链表是否为空
int IsEmptyList(pNode pHead);
//输出打印链表
void PrintList(pNode pHead);
//计算链表长度
int GetListLength(pNode pHead);
//从链表中插入节点,这里之后有读写操作的operation
int InsertEleList(pNode pHead,int pos,int LPN,int operation);
//向链表中删除节点
int DeleteEleList(pNode pHead,int pos);
//删除整个链表，释放内存
void FreeList(pNode *ppHead);
//从链表中找到特定的LPN值，并返回节点的指针位置,如果不存在返回NULL
pNode FindLPNinList(pNode pHead,int LPN);
//找到剔除项AD-LRU的二次机会，返回的是要剔除的项的指针
pNode FindVicitmList(pNode pHad);
int MoveToHotMRU(pNode HHead,pNode HitNode);
int DelLRUList(pNode pHead);
pNode FindLPNInBuffer(int LPN,int operation);
double ComputeCacheDelay();
double CacheManage(int secno,int scount,int operation );
void PrintBufferStat();
#endif
